<?php
/*
 * 用户管理器
 */
require DOCMENT_ROOT.'/Framework/controller.class.php';
class userController extends controller{
    public function __construct(){
        parent::header();
        parent::smartyAction("Index");
    }
    /**
     * 展示注册页面
     */
    public function register(){
        $this->smarty->display("register.html");
    }
      public function login(){
        $this->smarty->display("login.html");
    }
    /*
     * 验证用户名
     */
    public function checkName(){
        $name= $_GET["name"];
        //数据库验证是否重复
        require DOCMENT_ROOT."/Application/Index/model/userModel.class.php";
        $userModel=new userModel();
        $result=$userModel->checkField("name='$name'");
        if($result){
            echo "用户名可以使用";
        }else{
             echo "用户名已经存在";
        }
    }  
    /*
     * 验证邮箱
     */
     public function checkEmail() {
        $email = $_GET["email"];
        $preg ="/^\w{5,15}@(([a-zA-Z0-9]){2,3}\.)+[a-z]{2,4}$/";
        $c = preg_match($preg, $email);
        if($c == 0){
        echo 2;
        } else {
        echo 1;
        }
    }
    
     /*
     * 手机邮箱
     */
    public function checkTel(){
            $tel = $_GET["tel"];
            $preg ="/^1[0-9]{10}$/";//这是手机的
            $d = preg_match($preg, $tel);
            if($d == 0){
                echo 2;
            }else {
               echo 1;
            }
    }
    /*
     * 存储用户信息
     */
     public function addUser(){
    	$name = $_POST["name"];
    	$pwd = $_POST["pwd"];
    	$nickName = $_POST["nickname"];
    	$email = $_POST["email"];
    	$tel = $_POST["tel"];
    //插入信息
    	require DOCMENT_ROOT."/Application/Index/model/userModel.class.php";
    	$usermodel =new userModel();
    	$result =$usermodel->addUser($name,$pwd,$nickName,$email,$tel);
    	echo $result;
    	
    }
  
     /*
     * 登录
     */
    public function checklogin(){
            $name = $_GET["name"];
            $pwd =$_GET["pwd"];
            require DOCMENT_ROOT."/Application/Index/model/userModel.class.php";
            $userModel=new userModel();
            $result = $userModel->login("$name","$pwd");
            echo $result;
    }
    //修改
    public function userupdateSmarty(){
        $id=$_GET["id"];
        require DOCMENT_ROOT."/Application/Index/model/userModel.class.php";
        $userModel=new userModel();
        $arr=$userModel->userselect($id);
        $this->smarty->assign("arr",$arr[0]);
        $this->smarty->display("userupdate.html");    
        }
    public function userupdate(){
        $id=$_POST["id"];
        $nick_name=$_POST["nick_name"];
        $pwd=$_POST["pwd"];
        $email=$_POST["email"];
        $tel=$_POST["tel"];
        //调取数据
         require DOCMENT_ROOT."/Application/Index/model/userModel.class.php";
         $userModel=new userModel();
        $arr=$userModel->updateOne($nick_name,$pwd,$id,$email,$tel);
    }
}
   
